package wwl.lsf.hellospringboot.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import lombok.Data;

/**
 * @Title
 * @Author wangwenliang
 * @Date 2020/7/14
 * @Description
 */
@Data
public class XssVo {

  private String name;
  private String age;

  private String sanDi;


  public static void main(String[] args) throws JsonProcessingException {

    XssVo xssVo = new XssVo();
    xssVo.setSanDi("帅气");
    String s = toUnderlineJSONString(xssVo);
    System.out.println("s = " + s);

  }
  public static String toUnderlineJSONString(Object object) throws JsonProcessingException {
    ObjectMapper mapper = new ObjectMapper();

    mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);

    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

    String reqJson = mapper.writeValueAsString(object);

    return reqJson;

  }
}
